//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    addressList:[]
  },
//设置选中地址为默认地址
/*
  selectTap: function (e) {
    console.log(e)
    var id = e.currentTarget.dataset.id;
    const db = wx.cloud.database()
    db.collection('useraddress').doc(id).update({
      data: {
       dateAdd:new Date()
      },
      success: function(res) {
        console.log(res)
        wx.navigateBack()
      }
    })
  
  },*/

  addNotice : function () {
    wx.navigateTo({
      url:"/pages/sys/notice/addnotice"
    })
  },
  
  editnotice: function (e) {
    wx.navigateTo({
      url: "/pages/sys/notice/addnotice?id=" + e.currentTarget.dataset.id
    })
  },
  
  onLoad: function () {
    console.log('onLoad')

   
  },
  onShow : function () {

    if(wx.getStorageSync('userid')){
        this.initShippingAddress();
    }else{
      wx.showModal({
        title: '提示',
        content: '请登录！',
        showCancel: true
      })
     
      return
    }
  },
  initShippingAddress: function () {
    var that = this;
    const db = wx.cloud.database()
    db.collection('noticeList').where({
     
    }).orderBy('dateAdd','desc').get({
      success: function(res)  {
        console.log(res)
        if (res.data.length > 0) {
          that.setData({
            addressList:res.data
          });
        } else {
          that.setData({
            addressList: null
          });
        }
      }
    })
  }

})
